#include "attendstatus.h"
#include "ui_attendstatus.h"

AttendStatus::AttendStatus(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::AttendStatus)
{
    ui->setupUi(this);

    connect(this,&AttendStatus::signal_attendStatus,[=](int t_type,int sum,int value)
    {
        switch(t_type)
        {
        case NATIVE:type = NATIVE;update();
            break;
        case MAN:type = MAN;update();
            break;
        case CITY:type = CITY;update();
            break;
        case ZERO: type = ZERO;update();
        }
    });
}

AttendStatus::~AttendStatus()
{
    delete ui;
}

void AttendStatus::setValue(int type, int value)
{
    switch(type)
    {
    case NATIVE: native_num = value;
        break;
    case MAN:man_num = value;
        break;
    case CITY:city_num = value;
        break;
    case ZERO:zero_num = value;
        break;
    }
}

void AttendStatus::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing);     //抗锯齿
    const int offset = 12;

    if(type == NATIVE)
    {
        QPen pen(Qt::gray,5);
        painter.setPen(pen);
        int x = this->width()/2;
        int y = this->height()/2;
        int radius_x = this->width()/3;
        int radius_y = this->height()/3;
        painter.drawEllipse(QPoint(x,y),radius_x,radius_y);

        QFont font("微软雅黑",11);
        painter.setFont(font);
        painter.setPen(QPen(Qt::black));
        painter.drawText(QPoint(x - offset,y - offset),"活跃");
        painter.setPen(QPen(QColor(0,200,0),5));
        painter.drawText(QPoint(x - offset,y + offset),"70%");


        //绘制圆弧    圆弧所在的外切矩形, 圆弧起始角度  圆弧的角度  (0~5760)
        painter.drawArc(x - radius_x,y - radius_y,2*radius_x,2*radius_y,0,4032);

    }else if(type == MAN){
        QPen pen(Qt::gray,5);
        painter.setPen(pen);
        int x = this->width()/2;
        int y = this->height()/2;
        int radius_x = this->width()/3;
        int radius_y = this->height()/3;
        painter.drawEllipse(QPoint(x,y),radius_x,radius_y);

        QFont font("微软雅黑",11);
        painter.setFont(font);
        painter.setPen(QPen(Qt::black));
        painter.drawText(QPoint(x - offset,y - offset),"男");
        painter.setPen(QPen(QColor(247,223,74),5));
        painter.drawText(QPoint(x - offset,y + offset),"20%");

        //绘制圆弧    圆弧所在的外切矩形, 圆弧起始角度  圆弧的角度  (0~5760)
        painter.drawArc(x - radius_x,y - radius_y,2*radius_x,2*radius_y,0,1152);

    }else if(type == CITY){
    QPen pen(Qt::gray,5);
    painter.setPen(pen);
    int x = this->width()/2;
    int y = this->height()/2;
    int radius_x = this->width()/3;
    int radius_y = this->height()/3;
    painter.drawEllipse(QPoint(x,y),radius_x,radius_y);

    QFont font("微软雅黑",11);
    painter.setFont(font);
    painter.setPen(QPen(Qt::black));
    painter.drawText(QPoint(x - offset,y - offset),"郴州");
    painter.setPen(QPen(QColor(235,0,0),5));
    painter.drawText(QPoint(x - offset,y + offset),"5%");

    //绘制圆弧    圆弧所在的外切矩形, 圆弧起始角度  圆弧的角度  (0~5760)
    painter.drawArc(x - radius_x,y - radius_y,2*radius_x,2*radius_y,0,288);
    }
    else if(type == ZERO){
        QPen pen(Qt::gray,5);
        painter.setPen(pen);
        int x = this->width()/2;
        int y = this->height()/2;
        int radius_x = this->width()/3;
        int radius_y = this->height()/3;
        painter.drawEllipse(QPoint(x,y),radius_x,radius_y);

        QFont font("微软雅黑",11);
        painter.setFont(font);
        painter.setPen(QPen(Qt::black));
        painter.drawText(QPoint(x - offset,y - offset),"00后");
        painter.setPen(QPen(QColor(28,210,205),5));
        painter.drawText(QPoint(x - offset,y + offset),"5%");

        //绘制圆弧    圆弧所在的外切矩形, 圆弧起始角度  圆弧的角度  (0~5760)
        painter.drawArc(x - radius_x,y - radius_y,2*radius_x,2*radius_y,0,288);
        }
}
